﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace SharpSoft.WPF.Validations
{
    /// <summary>
    /// 自定义验证规则
    /// </summary>
    public class CustomValidationRule : System.Windows.Controls.ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (CustomValidation != null)
            {
                return this.CustomValidation.Invoke(this, value, cultureInfo);
            }
            return ValidationResult.ValidResult;
        }
        /// <summary>
        /// 用于在事件处理程序中对值进行验证
        /// </summary>
        public event CustomValidationEventHandler CustomValidation;
    }

    public delegate ValidationResult CustomValidationEventHandler(ValidationRule rule, object value, CultureInfo cultureInfo);
}
